﻿/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：CNVP_Branks.cs
* 创建标识：曾乃强 15158756652 2011-03-17 11:03:01
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using CNVP.Framework.Helper;
using CNVP.Config;

namespace CNVP.JShop.DAL
{
    /// <summary>
    /// 对*CNVP_Branks*操作数据库(针对SQL Server)的实现
    /// </summary>
    public class CNVP_Branks
    {
       private string Prefix = DBConfig.Prefix;
        #region DAL
        public int Insert(Model.CNVP_Branks obj)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into  " + Prefix + "Branks ([BrankName],[BrankAddress],[BrankPic],[OrderID],[BrankOtherName],[IsDetele],[BrankDetail])");
            sql.Append("values(@BrankName,@BrankAddress,@BrankPic,@OrderID,@BrankOtherName,@IsDetele,@BrankDetail)");
            
            SqlParameter[] pra = {
                            new SqlParameter("@BrankName",obj.BrankName),
							new SqlParameter("@BrankAddress",obj.BrankAddress),
							new SqlParameter("@BrankPic",obj.BrankPic),
							new SqlParameter("@OrderID",obj.OrderID),
							new SqlParameter("@BrankOtherName",obj.BrankOtherName),
							new SqlParameter("@IsDetele",obj.IsDetele),
							new SqlParameter("@BrankDetail",obj.BrankDetail)
                                 };
            return DbHelper.ExecuteNonQuery(sql.ToString(), pra);
        }

        public int Update(Model.CNVP_Branks obj)
        {
             StringBuilder sql = new StringBuilder();
             sql.Append("update " + Prefix + "Branks set [BrankName] = @BrankName,[BrankAddress] = @BrankAddress,[BrankPic] = @BrankPic,[OrderID] = @OrderID,[BrankOtherName] = @BrankOtherName,[BrankDetail] = @BrankDetail where [ID] = @ID");

            SqlParameter[] pra = { 
                            new SqlParameter("@ID",obj.ID),
							new SqlParameter("@BrankName",obj.BrankName),
							new SqlParameter("@BrankAddress",obj.BrankAddress),
							new SqlParameter("@BrankPic",obj.BrankPic),
							new SqlParameter("@OrderID",obj.OrderID),
							new SqlParameter("@BrankOtherName",obj.BrankOtherName),
							new SqlParameter("@BrankDetail",obj.BrankDetail)
                                };
             return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }

        public int Delete(Model.CNVP_Branks obj)
        {
           StringBuilder sql = new StringBuilder();
           sql.Append("delete from " + Prefix + "Branks where [ID] = @ID");
           SqlParameter[] pra = {
                                new SqlParameter("@ID",obj.ID)
						
                                };
           return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }

        public List<Model.CNVP_Branks> LoadAll()
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[BrankName],[BrankAddress],[BrankPic],[OrderID],[BrankOtherName],[IsDetele],[BrankDetail] from " + Prefix + "Branks");
            DataTable DT = DbHelper.ExecuteTable(sql.ToString());
            List<Model.CNVP_Branks> list=new List<Model.CNVP_Branks>();
            if (DT != null && DT.Rows.Count > 0)
            {
                foreach (DataRow dr in DT.Rows)
                {
                    Model.CNVP_Branks cnvp_branks = new Model.CNVP_Branks();
                    cnvp_branks.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                    cnvp_branks.BrankName = dr["BrankName"] is DBNull ? String.Empty : (string)dr["BrankName"];
                    cnvp_branks.BrankAddress = dr["BrankAddress"] is DBNull ? String.Empty : (string)dr["BrankAddress"];
                    cnvp_branks.BrankPic = dr["BrankPic"] is DBNull ? String.Empty : (string)dr["BrankPic"];
                    cnvp_branks.OrderID = dr["OrderID"] is DBNull ? 0 : (int)dr["OrderID"];
                    cnvp_branks.BrankOtherName = dr["BrankOtherName"] is DBNull ? String.Empty : (string)dr["BrankOtherName"];
                    cnvp_branks.IsDetele = dr["IsDetele"] is DBNull ? (byte)0 : (byte)dr["IsDetele"];
                    cnvp_branks.BrankDetail = dr["BrankDetail"] is DBNull ? String.Empty : (string)dr["BrankDetail"];
                    list.Add(cnvp_branks);
                }
            }
            return list;

        }

        public Model.CNVP_Branks LoadById(int ID)
        {
            
            StringBuilder sql = new StringBuilder();
            sql.Append("select [BrankName],[BrankAddress],[BrankPic],[OrderID],[BrankOtherName],[IsDetele],[BrankDetail] from " + Prefix + "Branks");
            sql.Append(" where [ID] = @ID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ID",ID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            Model.CNVP_Branks cnvp_branks = new Model.CNVP_Branks();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_branks.BrankName = dr["BrankName"] is DBNull ? String.Empty : (string)dr["BrankName"];
                cnvp_branks.BrankAddress = dr["BrankAddress"] is DBNull ? String.Empty : (string)dr["BrankAddress"];
                cnvp_branks.BrankPic = dr["BrankPic"] is DBNull ? String.Empty : (string)dr["BrankPic"];
                cnvp_branks.OrderID = dr["OrderID"] is DBNull ? 0 : (int)dr["OrderID"];
                cnvp_branks.BrankOtherName = dr["BrankOtherName"] is DBNull ? String.Empty : (string)dr["BrankOtherName"];
                cnvp_branks.IsDetele = dr["IsDetele"] is DBNull ? (byte)0 : (byte)dr["IsDetele"];
                cnvp_branks.BrankDetail = dr["BrankDetail"] is DBNull ? String.Empty : (string)dr["BrankDetail"];
            } 
            return cnvp_branks;
        }

        #endregion

        public DataTable GetPage(string PageName, int PageIndex, int PageSize, out int RecordCount, out int PageCount, params SQLConditionInfo[] SqlCondition)
        {
            try
            {
                string AllFields = " ID, BrankName, BrankAddress, BrankPic, OrderID, BrankOtherName, IsDetele, BrankDetail";
                string Condition = "" + Prefix + "Branks";
                string IndexField = "ID";
                string OrderFields = "order by Id Desc";
                return DbHelper.ExecutePage(AllFields, Condition, IndexField, OrderFields, PageIndex, PageSize, out RecordCount, out PageCount, null);
            }
            catch (Exception e)
            {
                throw new Exception("用于分页的SQL语句无效:" + e.Message);
            }

        }
    }
}

